function CarController(model, view) {
	this.model = model;
	this.view = view;
	
	var cc = this;
	
	this.init = function() {
        //this.model.loadRoles(roles);
        $('#car_form_send').click(function() {
                cc.saveCar(this);
        });
        $('.place_action').click(function() {
                cc.changePlace(this);
        });
    },
	
	/*
	 *
	 */
	this.saveCar = function() {
            
        var item = new Object();
        item['model']           = $("#car_form_model").val();
        item['output_year']     = $("#car_form_output_year").val();
        item['insurance']       = $("#car_form_insurance").val();
        item['price']           = $("#car_form_price").val();
        item['start_place']  = $("#car_form_start_place").val();

            var action = $("#car_form_action").val();
            if (action == "edit") {
                item['id'] = $("#car_form_id").val();
                this.model.edit(item);

            } else if (action == "add") {
                this.model.add(item);
            } 
	},
	
	this.changePlace = function(e) {
            
        var str = "place_action_";
	    var id = $(e).attr('id').substr(str.length);
        var action = $(e).html();

        if (action == "add") {
            this.model.changePlace(id, "delete", this.view.delPlace);
        }

        if (action == "delete") {
            this.model.changePlace(id, "add", this.view.addPlace);
        }
    }
	
}

